-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: differentiate scalar parsing from byte arrays #194
feat!: differentiate scalar parsing from byte arrays #194
Conversation
7851f06
to
5d8b7f0
Compare
3f40bd1
to
7bcb57e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits re: one of the comments. Otherwise LGTM
ACK |
ddc40c7
to
bec8195
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, just some comments:
- Why force
from_bytes
to use the underlyingfrom_canonical_bytes
call? Why not add an additional methodfrom_canonical_bytes
method to use the underlyingfrom_canonical_bytes
call? This way the change will be non-breaking. - If the intention is to prohibit the underlying
from_bytes_mod_order
call, I would propose changing the name offrom_bytes
tofrom_canonical_bytes
.
@hansieodendaal thanks for the review.
There's no good reason to have scalar parsing use the underlying
Unfortunately implementing |
23196b3
to
26c3105
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
26c3105
to
7d10338
Compare
After discussion, it sounds like the preferred approach is to rename the |
7d10338
to
77293d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, sensible and easy to reason about.
ACK
9269e2b
to
e3279bf
Compare
e3279bf
to
a000006
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description --- Updates key parsing to differentiate between canonical- and reduction-based use cases. Makes several updates to account for `EpochTime` changes. Updates genesis data. Motivation and Context --- An [update](tari-project/tari-crypto#194) to `tari-crypto` differentiates secret key parsing between cases that should use canonical byte arrays, and those that use random byte arrays requiring modular wide reduction. This PR makes corresponding changes to account for this. It also makes several updates required since the `tari_utilities` release used here also makes breaking `EpochTime` changes that can't be cleanly done separately. How Has This Been Tested? --- Existing tests pass. Uses of parsed secret keys have been manually inspected for correctness. What process can a PR reviewer use to test or verify this change? --- Assert that secret keys and scalars instantiated from byte arrays use the appropriate approach: parsing from canonical byte arrays, or modular wide reduction from uniform byte arrays. Confirm that `EpochTime` changes reflect the intended logic, especially relating to timestamp and difficulty handling. BREAKING CHANGE: This modifies how secret keys and scalars are constructed and is therefore a breaking change. --------- Co-authored-by: Aaron Feickert <[email protected]>
Currently, creating a scalar
RistrettoSecretKey
from a byte array performs modular reduction on 32 bytes. For cases where the input is intended to be canonical, this is suboptimal. For cases where the input is produced from a hashing operation, wide reduction should be used to mitigate bias.This work renames
SecretKey::from_bytes
toSecretKey::from_canonical_bytes
to support an underlyingByteArray
trait update. In the case ofRistrettoSecretKey
, it uses the curve library's canonical parser and returns an error if the provided byte slice is not a canonical scalar encoding.It also adds a new
SecretKey::from_uniform_bytes
function that uses wide reduction. For constructions like signatures and KDFs that use hashing operations to produce scalar values, this function is used and the underlying hashers are updated to produce 64-byte output in the case ofRistrettoSecretKey
.It updates the Schnorr signature API to support raw signing and verification using challenge byte slices that are either canonical encodings or uniform. It renames several existing functions for clarity.
It corrects a few typos that were discovered along the way.
Closes #189.
BREAKING CHANGE: This changes the way that scalars are produced from byte arrays, modifies the
SecretKey
trait and correspondingRistrettoSecretKey
implementation, and updates the Schnorr signature API.